# python 中的 * 和 **

# *在参数中的运用，作为可变长参数
def test_args(first, *args):
    print('Required argument is ', first)
    print(type(args))
    for v in args:
        print('Optional argument: ', v)


# *args接收多个value，将其合并为一个tuple；**kwargs接收多个 k=value 将其合成一个dict
def test_args_kwargs(first, *args, **kwargs):
    print('Required argument is : ', first)
    print("type of *args is", type(args))
    for v in args:
        print('Optional argument (args): ', v)
    print("type of **kwargs is", type(kwargs))
    for k, v in kwargs.items():
        print('Optional argument %s (kwargs): %s' % (k, v))


# *在返回值中的应用，追加写入值到tuple中
def test_return_args():
    args = (1, 2, 3)
    return (*args, 4, 5)


# **在返回值中的应用，追加写入值到dict中
def test_return_kwargs():
    kwargs = {'status': 'merge_success', 'dup_resources': []}
    return {**kwargs, 'msg': 'resource_file_success'}


if __name__ == '__main__':
    # test_args(1, 2, 3, 4)
    # test_return_value = test_return()
    # print("type of test_return_value is", type(test_return_value))
    # print(test_return_value)
    # test_args_kwargs(1, 2, 3, 4, k1=5, k2=6)
    print(test_return_args())
